<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/10/13
 * Time: 22:07
 */
namespace app\model;


use think\facade\Db;
use think\Model;

class GoodsExchange extends Model
{

    private function _getListField()
    {
        return [
            'ge_id' => 'goodsExchangeId',
            'ge_pername' => 'pername',
            'ge_goods_name' => 'name',
            'goods_stock' => 'stock',
            'ge_status' => 'status',
            'ge_exchange_status' => 'exchangeStatus',
            'ge_create_time' => 'createTime'
        ];
    }

    public function getGoodsExchangeInfoById($goodsExchangeId,$field = '')
    {
        $field = $field ?: self::_getListField();
        return Db::table('goods_exchange')
            ->leftJoin('goods','goods_id=ge_goods_id')
            ->where(['ge_id'=>$goodsExchangeId])
            ->field($field)
            ->find();
    }
    public function addOneExchange($data)
    {
        $data['ge_create_time'] = time();
        return Db::table('goods_exchange')->insertGetId($data);
    }

    public function getGoodsExchangeListByCondition($where = [],$order = 'ge_id desc',$field = '')
    {
        $field = $field ?: self::_getListField();
        $list = Db::table('goods_exchange')
            ->leftJoin('goods','goods_id=ge_goods_id')
            ->where($where)
            ->field($field)
            ->order($order)
            ->paginate(input('param.pageSize'))
            ->render();
        return $list;
    }

    public function updateGoodsExchangeInfoByWhere($where,$data)
    {
        $data['ge_update_time'] = time();
        return Db::table('goods_exchange')->where($where)->update($data);
    }

}